package com.ruoyi.exam.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exam.domain.ExamUniversity;
import com.ruoyi.exam.service.IExamUniversityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 学校管理Controller
 * 
 * @author wky
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/exam/university")
@Tag(name = "【学校管理】管理")
public class ExamUniversityController extends BaseController
{
    @Autowired
    private IExamUniversityService examUniversityService;

    /**
     * 查询学校管理列表
     */
    @Operation(summary = "查询学校管理列表")
    @PreAuthorize("@ss.hasPermi('exam:university:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamUniversity examUniversity)
    {
        startPage();
        List<ExamUniversity> list = examUniversityService.selectExamUniversityList(examUniversity);
        return getDataTable(list);
    }

    /**
     * 导出学校管理列表
     */
    @Operation(summary = "导出学校管理列表")
    @PreAuthorize("@ss.hasPermi('exam:university:export')")
    @Log(title = "学校管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamUniversity examUniversity)
    {
        List<ExamUniversity> list = examUniversityService.selectExamUniversityList(examUniversity);
        ExcelUtil<ExamUniversity> util = new ExcelUtil<ExamUniversity>(ExamUniversity.class);
        util.exportExcel(response, list, "学校管理数据");
    }

    /**
     * 获取学校管理详细信息
     */
    @Operation(summary = "获取学校管理详细信息")
    @PreAuthorize("@ss.hasPermi('exam:university:query')")
    @GetMapping(value = "/{universityId}")
    public AjaxResult getInfo(@PathVariable("universityId") Long universityId)
    {
        return success(examUniversityService.selectExamUniversityByUniversityId(universityId));
    }

    /**
     * 新增学校管理
     */
    @Operation(summary = "新增学校管理")
    @PreAuthorize("@ss.hasPermi('exam:university:add')")
    @Log(title = "学校管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamUniversity examUniversity)
    {
        return toAjax(examUniversityService.insertExamUniversity(examUniversity));
    }

    /**
     * 修改学校管理
     */
    @Operation(summary = "修改学校管理")
    @PreAuthorize("@ss.hasPermi('exam:university:edit')")
    @Log(title = "学校管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamUniversity examUniversity)
    {
        return toAjax(examUniversityService.updateExamUniversity(examUniversity));
    }

    /**
     * 删除学校管理
     */
    @Operation(summary = "删除学校管理")
    @PreAuthorize("@ss.hasPermi('exam:university:remove')")
    @Log(title = "学校管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{universityIds}")
    public AjaxResult remove(@PathVariable( name = "universityIds" ) Long[] universityIds) 
    {
        return toAjax(examUniversityService.deleteExamUniversityByUniversityIds(universityIds));
    }
}
